package com.monlyu.bo;

import java.text.NumberFormat;
import java.util.Iterator;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.monlyu.util.DateUtil;
import com.monlyu.util.MathUtil;
import com.monlyu.vo.GaoJian2Reporter;
import com.monlyu.vo.Manuscript;

/*******************************************************************************
 * 
 * <b>功能描述☞</b>设置201005记录发稿条数<br>
 * 
 * <b>开发公司☞</b>重庆唯尼科技有限公司<br>
 * <b>版权☞</b>本文件归重庆唯尼科技有限公司所有<br>
 * <b>项目名☞</b>newsH<br>
 * <b>文件路径☞</b>com.monlyu.bo.SetFGCountBo.java<br>
 * <b>开发日期☞</b>2010-6-28 <br>
 * 
 * @author chendan
 * @since JDK 5
 * @version 1.0.8
 * 
 ******************************************************************************/
@Repository(value = "setFGCountBo")
public class SetFGCountBo extends BaseBo {

	public void setfgCount() {
		String hql = "select distinct g.manuscript from com.monlyu.vo.GaoJian2Reporter g "
				+ " where g.score>0 and g.scoreDate is not null";
		List<Manuscript> manuscripts = dao.find(hql);
		for (Iterator<Manuscript> it = manuscripts.iterator(); it.hasNext();) {
			Manuscript manuscript = it.next();
			hql = "from  com.monlyu.vo.GaoJian2Reporter g  where  g.manuscript=?";
			List<GaoJian2Reporter> gaojian2Reporters = dao
					.find(hql, manuscript);
			if (gaojian2Reporters != null) {
				int size = gaojian2Reporters.size();
				float count = MathUtil.formatFraction(1.0f / size, 1);
				for (Iterator<GaoJian2Reporter> iterator = gaojian2Reporters
						.iterator(); iterator.hasNext();) {
					GaoJian2Reporter ggReporter = iterator.next();
					ggReporter.setFgCount(count);
					dao.update(ggReporter);
				}
			}
		}
	}
}
